﻿let webconfig = require("../../webconfig").webconfig;

/**
 * 用于读取服务模块工作的单例对象
 * 
 * @export
 * @class ServiceConfig 
 */
export class ServiceConfig {
    static Current: ServiceConfig = new ServiceConfig();
    private serverModules;
    constructor() {
        this.serverModules = webconfig;
    }

    /**
     * 获取服务模块对象实例
     * 
     * @template T 服务模块对象类型
     * @param {any} svrName 服务名称
     * @returns {T} 服务模块对象实例
     * 
     * @memberOf ServiceConfig
     */
    GetService<T>(svrName): T {
        let svr = this.serverModules.baseService[svrName];
        if (svr) {
            let r = require("../" + svr.src);
            return new (r[svr.className])();
        }
        return null;
    }
}